package com.dance.spring.learn.testdemo;

import com.dance.spring.learn.aop.User;
import com.dance.spring.learn.autowire.Emp;
import com.dance.spring.learn.collection.Book;
import com.dance.spring.learn.collection.Course;
import com.dance.spring.learn.collection.Stu;
import com.dance.spring.learn.config.SpringConfig;
import com.dance.spring.learn.factorybean.MyBean;
import com.dance.spring.learn.factorybean.Orders;
import com.dance.spring.learn.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.annotation.Order;

public class TestSpring5Demo {

    @Test
    public void test1(){

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");

        Stu stu = applicationContext.getBean("stu", Stu.class);

        System.out.println(stu);

    }

    @Test
    public void test2(){

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");

        Book book = applicationContext.getBean("book", Book.class);

        System.out.println(book);

    }

    @Test
    public void test3(){

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");

        Course myBean = applicationContext.getBean("myBean", Course.class);

        System.out.println(myBean);

    }

    @Test
    public void test4(){

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");

        Book book1 = applicationContext.getBean("book", Book.class);
        Book book2 = applicationContext.getBean("book", Book.class);

        System.out.println(book1);
        System.out.println(book2);

    }

    @Test
    public void test5(){

        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring.xml");

        Orders orders = applicationContext.getBean("orders", Orders.class);
        System.out.println("生命周期调用链: 第四步");

        // 手动销毁容器
        applicationContext.close();

    }

    @Test
    public void test6(){

        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("Spring2.xml");

        Emp emp = applicationContext.getBean("emp", Emp.class);

        System.out.println(emp);

    }

    @Test
    public void test7(){
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("Spring3-annotation.xml");
        UserService userService = classPathXmlApplicationContext.getBean("userService", UserService.class);
        userService.add();
    }
    @Test
    public void test8(){
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("Spring4.xml");
        UserService userService = classPathXmlApplicationContext.getBean("userService", UserService.class);
        userService.add();
    }
    @Test
    public void test9(){
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = annotationConfigApplicationContext.getBean("userService", UserService.class);
        userService.add();
    }

    @Test
    public void test10(){
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("Spring-aop.xml");
        User user = classPathXmlApplicationContext.getBean("user", User.class);
        user.add();
    }

    @Test
    public void test11(){
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(com.dance.spring.learn.aop.config.SpringConfig.class);
        User user = annotationConfigApplicationContext.getBean("user", User.class);
        user.add();
    }

}
